var $ = require('../../../utils/helper.js'), that = null
var app = getApp()
Page({
  data: {

  },
  onLoad(e) {
    that = this
    let id = e.id
    that.setData({id:e.id})
    console.log(e.id)
  },
  onReady: function () {
    $.check(that)
  },
  init: function () {
    that.details()
  },
  details:function(){
    $.post("api/service/detail",{user_id:that.data.id},function(data){
      that.setData({info:data})
    })
  },
  praise:function(){
    $.post("api/service/great", {user_id: that.data.id, type: 1}, function (data){
       that.init()
    })
  },
  collect:function(){
    $.post("api/service/collect",{user_id:that.data.id,type:1},function(data){
      that.init()
    })
  },
  save: function () {
    wx.showLoading({
      title: '正在生成海报',
    })
    let poster_url = "https://yueyixing.beiyii.xyz/api/index/serviceposter?id=" + that.data.id
    wx.downloadFile({
      url: poster_url,
      success(res) {
        wx.hideLoading()
        if (res.statusCode === 200) {
          let file = res.tempFilePath
          wx.saveImageToPhotosAlbum({
            filePath: file,
            success: function () {
              getApp().toast("保存海报成功")
            }
          })
        }
      }
    })
  },
  contact: function () {
    $.post("api/index/contact", { user_id: that.data.id }, function (data) {
      that.setData({ contact_my: data })
    })
  },
  dialing:function(){
    wx.makePhoneCall({
      phoneNumber: that.data.info.tel
    })
  },
  
  map:function(){
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        wx.openLocation({
          latitude: that.data.info.latitude,
          longitude: that.data.info.longitude,
          scale: 28
        })
      }
    })
  }
}) 